<?php
/**
 * Created by PhpStorm.
 * User: DaibiDaddy
 * Date: 2016/6/3
 * Time: 14:59
 */

namespace App\Setting\LazyCommon;

use App\Model\LazyCommon\UserGroupsModel;

class UserGroupsSetting{

    /*手动获取的配置项*/
    public $catType = "level";//Options:level snake
    public $entityCnName = "用户组";
    public $table = "User_Groups";
    public $editKeys = array("orders","link");
    public $perPage = 10;

    /*自动获取的配置项*/
    public $entity;
    public $bundleName;
    public $entityName;
    public $SettingPath;
    public $entityPath;
    public $modelPath;
    public $doctrine;

    public function __construct($doctrine)
    {
        $this->bundleName = "App";
        $this->entityName = str_replace("\\","",str_replace("Setting","",str_replace(__NAMESPACE__,"",__CLASS__)));
        $this->SettingPath = __CLASS__;
        $this->entityPath = str_replace($this->entityName."Entity",$this->entityName,str_replace("Setting","Entity",str_replace("\\LazyCommon","",__CLASS__)));
        $this->entity = new $this->entityPath();
        $this->modelPath = str_replace("Setting","Model",__CLASS__);
        $this->modelPath = str_replace("Setting","Model",__CLASS__);
//        $this->modelPath = "App/LazyCommon";
        $this->doctrine = $doctrine;
    }

    public function listConfig()
    {
        $default = array();
        $default["User_Groups AS UserGroups"]["select"] = array("id","name","pic","info","orders","parent","level");
        $default["User_Groups AS UserGroups"]["search"] = array("name");
        $default["User_Groups AS UserGroups"]["condition"] = array("parent");
        $default["User_Groups AS UserGroups"]["orderBy"] = array();

        $join = array();

        return array(
            "default"   => $default,
            "joins"     => $join,
        );
    }

    public function formConfig()
    {
        $model = new UserGroupsModel($this->doctrine);
        $categories = $model->getAllUserGroupsTree();
        $parents[0] = "根目录";
        foreach ($categories as $c) {
            $parents[$c["id"]] = $c["name"];
        }
        $options["parent"]["other"] = array(
            "choices"   => array_flip($parents),
        );
        $config["parent"] = array(
            "label"     =>"父级ID",
            "showType"  =>"select",
            "dataType"  =>"required",
            "option"    => $options["parent"]
        );

        $config["name"] = array(
            "label"     =>"名称",
            "showType"  =>"text",
            "dataType"  =>"required",
            "option"    => array()
        );

        $config["orders"] = array(
            "label"     =>"排序",
            "showType"  =>"text",
            "dataType"  =>"required",
            "option"    => array()
        );

        $config["pic"] = array(
            "label"     =>"图标",
            "showType"  =>"pic",
            "dataType"  =>"",
            "option"    => array()
        );

        $config["info"] = array(
            "label"     =>"说明",
            "showType"  =>"textarea",
            "dataType"  =>"",
            "option"    => array()
        );
        return $config;
    }
}